// structstudentarray.c
// gcc structstudentarray.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct Student
{
    char name[10];
    int  eng;
    int  math;
}STUDENT;

void inputStudentArray(STUDENT *, int);
void printStudentArray(STUDENT *, int);

#define LEN 3

int main()
{
    STUDENT stu[LEN];
    
    inputStudentArray(stu, LEN);
    printStudentArray(stu, LEN);
    
    printf("\n");
    system("pause");
    return 0;
}

void inputStudentArray(STUDENT *pst, int len)
{
    for(int i=0 ; i < len ; i++)
    {
        printf("Student %d\n", i);
        printf("name : ");  gets( pst[i].name );
        
        printf("eng  : ");  scanf("%d", &pst[i].eng);  
        fflush(stdin);
        
        printf("math : ");  scanf("%d", &pst[i].math);
        fflush(stdin);
        printf("\n");
    }
}

void printStudentArray(STUDENT *pst, int len)
{
    printf("Name\tEng\tMath\tSum\tAvg\n");
    printf("---------------------------------------\n");
    for(int i = 0 ; i < len ; i++)
        printf("%s\t%d\t%d\t%d\t%.2f\n", 
               pst[i].name, 
               pst[i].eng, 
               pst[i].math,
               pst[i].eng + pst[i].math,
               (pst[i].eng + pst[i].math)/2.0);
}